package com.example.steriousfx.demo;

import cn.yeziji.http.tools.MRequest;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.protocol.HTTP;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author gzkemays
 * @since 2021/12/9 22:27
 */
public class OuchnLearnDemo {
  public String loginOuchn() throws Exception {
    HttpGet noDataGet = MRequest.getNoDataGet("http://guangzhou.ouchn.cn/course/view.php?id=2588");
    noDataGet.setHeader(
        "Cookie", "MoodleSession=6k3r2h22k6kguvdn72an696l70; username=1844101480323");
    noDataGet.setHeader(
        HTTP.USER_AGENT,
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43");
    return MRequest.getResultFromRequest(noDataGet);
  }

  public static void main(String[] args) {
    OuchnLearnDemo ouchnLearnDemo = new OuchnLearnDemo();
    try {
      String html = ouchnLearnDemo.loginOuchn();
      Document parse = Jsoup.parse(html);
      Elements aalink = parse.getElementsByClass("aalink");
      for (Element element : aalink) {
        String href = element.attr("href");
        if ("http://guangzhou.ouchn.cn/mod/url/view.php?id=337523".equals(href)) {
          HttpGet noDataGet =
              MRequest.getNoDataGet("http://guangzhou.ouchn.cn/mod/url/view.php?id=337523");
          noDataGet.setHeader(
              "Cookie", "MoodleSession=6k3r2h22k6kguvdn72an696l70; username=1844101480323");
          noDataGet.setHeader(
              HTTP.USER_AGENT,
              "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43");
          String resultFromRequest = MRequest.getResultFromRequest(noDataGet);
          System.out.println(resultFromRequest);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
